﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Acms.DatabaseTest.Helpers;

namespace Acms.DatabaseTest
{
    [TestClass]
    public class HelpersTest
    {
        [TestMethod]
        public void ConnectionTest()
        {
            using (var conn = TestConnection.Begin())
            {
                Assert.AreEqual(0, conn.Site_GetAll().Count);
            }
        }

        [TestMethod]
        public void AddTest()
        {
            using (var conn = TestConnection.Begin())
            {
                conn.Site_Add(1, "TestName", "TestRoot", true, false, false);
                var results = conn.Site_GetAll();
                Assert.AreEqual(1, results.Count);
                Assert.AreEqual("TestName", results.First()["Name"]);
                Assert.AreEqual("TestRoot", results.First()["Root"]);
                Assert.AreEqual(true, results.First()["UseTopics"]);
                Assert.AreEqual(false, results.First()["UseMenus"]);
                Assert.AreEqual(false, results.First()["Deleted"]);
            }
        }

        [TestMethod]
        public void RollbackTest()
        {
            using (var conn = TestConnection.Begin())
            {
                conn.Site_Add(1, "TestName", "TestRoot", true, false, false);
                Assert.AreEqual(1, conn.Site_GetAll().Count);
            }
            using (var conn = TestConnection.Begin())
            {
                Assert.AreEqual(0, conn.Site_GetAll().Count);
            }
        }

        [TestMethod]
        public void ExecuteProcTest()
        {
            using (var conn = TestConnection.Begin())
            {
                conn.Site_Add(1, "TestName", "TestRoot", true, false, false);
                Assert.AreEqual(1, conn.ExecuteProc("acms.Site_GetAll", new ParamCollection()).Count);
            }
        }
    }
}
